/**
 * 工作流API
 *
 * @版权所有 rem.studio
 */
import { stringify } from 'qs';
import request from '@/utils/request';

/** 模型API开始 */

export async function queryModel(params = {}) {
  return request(`/api/activiti/model/queryModel?${stringify(params)}`, {
    method: 'GET'
  });
}

export async function addModel(params) {
  return request('/api/activiti/model/addModel', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function updateModel(params) {
  return request('/api/activiti/model/updateModel', {
    method: 'PUT',
    requestType: 'form',
    data: {
      ...params.body
    }
  });
}

export async function deleteModel(params) {
  return request('/api/activiti/model/deleteModel', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function deployModel(params) {
  return request('/api/activiti/model/deployModel', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

/** 模型API结束 */
/** 流程API开始 */

export async function queryProcessDefinition(params = {}) {
  return request(`/api/activiti/process/queryProcessDefinition?${stringify(params)}`, {
    method: 'GET'
  });
}

export async function startProcessInstance(params) {
  return request('/api/activiti/process/startProcessInstance', {
    method: 'POST',
    data: {
      ...params
    }
  });
}

export async function suspendProcessDefinition(params) {
  return request('/api/activiti/process/suspendProcessDefinition', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function activateProcessDefinition(params) {
  return request('/api/activiti/process/activateProcessDefinition', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function persistProcess(params) {
  return request(`/api/activiti/process/persistProcess`, {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function getDesignProcessResource(params) {
  return request('/api/activiti/process/getProcessResource', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function getProcessResource(params) {
  return request('/api/activiti/process/getProcessImage', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function getProcessImage(params) {
  return request('/api/activiti/process/getProcessImage', {
    method: 'POST',
    requestType: 'form',
    responseType: 'blob',
    data: {
      ...params
    }
  });
}

export async function queryProcessInstance(params = {}) {
  return request(`/api/activiti/process/queryProcessInstance?${stringify(params)}`, {
    method: 'GET'
  });
}

export async function getHighLightedProcessDiagram(params) {
  return request('/api/activiti/process/getHighLightedProcessDiagram', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function suspendProcessInstance(params) {
  return request('/api/activiti/process/suspendProcessInstance', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function activateProcessInstance(params) {
  return request('/api/activiti/process/activateProcessInstance', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function deleteProcessInstance(params) {
  return request('/api/activiti/process/deleteProcessInstance', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function queryExecution(params = {}) {
  return request(`/api/activiti/process/queryExecution?${stringify(params)}`, {
    method: 'GET'
  });
}

/** 流程API结束 */
/** 部署API开始 */

export async function queryDeployment(params = {}) {
  return request(`/api/activiti/deployment/queryDeployment?${stringify(params)}`, {
    method: 'GET'
  });
}

export async function deleteDeployment(params) {
  return request('/api/activiti/deployment/deleteDeployment', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

/** 部署API结束 */
/** 任务API开始 */

export async function queryUsername() {
  return request('/api/activiti/task/queryUsername', {
    method: 'GET'
  });
}

export async function queryTask(params = {}) {
  return request(`/api/activiti/task/queryTask?${stringify(params)}`, {
    method: 'GET'
  });
}

export async function queryTaskComment(params = {}) {
  return request(`/api/activiti/task/queryTaskComment?${stringify(params)}`, {
    method: 'GET'
  });
}

/** 任务API结束 */
/** 流程任务历史API开始 */

export async function queryHistoricProcessInstance(params = {}) {
  return request(`/api/activiti/history/queryHistoricProcessInstance?${stringify(params)}`, {
    method: 'GET'
  });
}

export async function deleteHistoricProcessInstance(params) {
  return request(`/api/activiti/history/deleteHistoricProcessInstance`, {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function queryHistoricActivityInstance(params = {}) {
  return request(`/api/activiti/history/queryHistoricActivityInstance?${stringify(params)}`, {
    method: 'GET'
  });
}

export async function queryHistoricDetail(params = {}) {
  return request(`/api/activiti/history/queryHistoricDetail?${stringify(params)}`, {
    method: 'GET'
  });
}

export async function queryHistoricVariableInstance(params = {}) {
  return request(`/api/activiti/history/queryHistoricVariableInstance?${stringify(params)}`, {
    method: 'GET'
  });
}

export async function queryHistoricTaskInstance(params = {}) {
  return request(`/api/activiti/history/queryHistoricTaskInstance?${stringify(params)}`, {
    method: 'GET'
  });
}

export async function deleteHistoricTaskInstance(params) {
  return request(`/api/activiti/history/deleteHistoricTaskInstance`, {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

/** 流程任务历史API结束 */
/** 我的办公API开始 */

export async function queryPersonalTask(params = {}) {
  return request(`/api/activiti/task/queryPersonalTask?${stringify(params)}`, {
    method: 'GET'
  });
}

export async function claimTask(params) {
  return request('/api/activiti/task/claimTask', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function completeTask(params) {
  return request('/api/activiti/task/completeTask', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function delegateTask(params) {
  return request('/api/activiti/task/delegateTask', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function resolveTask(params) {
  return request('/api/activiti/task/resolveTask', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function regressTask(params) {
  return request('/api/activiti/task/regressTask', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function rejectTask(params) {
  return request('/api/activiti/task/rejectTask', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

export async function terminateTask(params) {
  return request('/api/activiti/task/terminateTask', {
    method: 'POST',
    requestType: 'form',
    data: {
      ...params
    }
  });
}

/** 我的办公API结束 */
